<template>
  <div class="container">
    <div class="card" style="min-height: 85vh;">
      <div class="blog-detail">
        <h1 class="blog-title">{{ news.title }}</h1>
        <div class="blog-meta" style="display: flex; align-items: center; margin-bottom: 20px;">
          <span style="color: #666; margin-right: 20px"><i class="el-icon-date"></i> {{ news.createdAt }}</span>
        </div>
        <div class="blog-image" v-if="news.img">
          <img style="width: 100%; border-radius: 5px;" :src="news.img" alt="公告图片">
        </div>
        <div class="blog-content" v-html="news.content"></div>
      </div>
    </div>
  </div>
</template>

<script  setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { getAnnouncementByIdService } from '@/api/announcement.js'

const route = useRoute()
const id = route.query.id
const news = ref({})

const fetchNewsDetail = async () => {
  try {
    const response = await getAnnouncementByIdService(id)
    news.value = response.data
  } catch (error) {
    console.error('获取公告详情失败', error)
  }
}

onMounted(() => {
  fetchNewsDetail()
})
</script>

<style scoped>
.container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  background-color: #f9f9f9;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.card {
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
}

.blog-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 10px;
  color: #333;
}

.blog-meta {
  font-size: 14px;
  color: #666;
}

.blog-content {
  margin-bottom: 20px;
}

.blog-image img {
  width: 100%;
  border-radius: 5px;
}
</style>